--- ../tk4.1/generic/tk3d.c	Fri Feb 16 22:31:04 1996
+++ tk3d.c	Mon Jul  8 19:24:09 1996
@@ -12,6 +12,10 @@
  *
  * SCCS: @(#) tk3d.c 1.52 96/02/15 18:51:30
  */
+/*
+ * TkSTEP modifications Copyright by
+ * Alfredo K. Kojima
+ */
 
 #include "tkPort.h"
 #include "tkInt.h"
@@ -55,6 +59,9 @@
     GC lightGC;			/* Used to draw lighter parts of
 				 * the border. None means the shadow colors
 				 * haven't been allocated yet. */
+    GC dark2GC;			/* Used to draw even darker part of shadows
+				 * (black)
+				 */
     Tcl_HashEntry *hashPtr;	/* Entry in borderTable (needed in
 				 * order to delete structure). */
 } Border;
@@ -166,6 +173,7 @@
 	borderPtr->shadow = None;
 	borderPtr->bgGC = None;
 	borderPtr->darkGC = None;
+	borderPtr->dark2GC = None;
 	borderPtr->lightGC = None;
 	borderPtr->hashPtr = hashPtr;
 	Tcl_SetHashValue(hashPtr, borderPtr);
@@ -235,21 +243,52 @@
     Border *borderPtr = (Border *) border;
     GC left, right;
     Display *display = Tk_Display(tkwin);
-
+    int half;
+    
+    
     if ((borderPtr->lightGC == None) && (relief != TK_RELIEF_FLAT)) {
 	GetShadows(borderPtr, tkwin);
     }
+    
     if (relief == TK_RELIEF_RAISED) {
-	XFillRectangle(display, drawable, 
-		(leftBevel) ? borderPtr->lightGC : borderPtr->darkGC,
-		x, y, (unsigned) width, (unsigned) height);
+	if (width > 1) {
+	    if (leftBevel) {
+	        left = borderPtr->lightGC;
+	        right = borderPtr->bgGC;
+	    } else {
+	        left = borderPtr->darkGC;
+	        right = borderPtr->dark2GC;
+	    }
+	    half = width/2;
+	    XFillRectangle(display, drawable, left,
+	 	x, y, (unsigned) half, (unsigned) height);
+	    XFillRectangle(display, drawable, right,
+		x+half, y, (unsigned) (width - half), (unsigned) height);
+	} else {
+	    left = (leftBevel) ? borderPtr->lightGC : borderPtr->dark2GC;
+	    XFillRectangle(display, drawable, left,
+	 	x, y, (unsigned) width, (unsigned) height);	
+ 	}
     } else if (relief == TK_RELIEF_SUNKEN) {
-	XFillRectangle(display, drawable, 
-		(leftBevel) ? borderPtr->darkGC : borderPtr->lightGC,
-		x, y, (unsigned) width, (unsigned) height);
+	if (width > 1) {
+	    if (leftBevel) {
+	    	left = borderPtr->darkGC;
+	    	right = borderPtr->dark2GC;	    
+	    } else {
+	    	left = borderPtr->bgGC;
+	   	right = borderPtr->lightGC;
+	    }
+	    half = width/2;
+	    XFillRectangle(display, drawable, left, 
+		x, y, (unsigned) half, (unsigned) height);
+	    XFillRectangle(display, drawable, right, 
+		x + half, y, (unsigned) (width - half), (unsigned) height);
+        } else {
+	    left = (leftBevel) ? borderPtr->dark2GC : borderPtr->lightGC;
+	    XFillRectangle(display, drawable, left,
+	 	x, y, (unsigned) width, (unsigned) height);
+    	}
     } else if (relief == TK_RELIEF_RIDGE) {
-	int half;
-
 	left = borderPtr->lightGC;
 	right = borderPtr->darkGC;
 	ridgeGroove:
@@ -333,12 +372,20 @@
 
     switch (relief) {
 	case TK_RELIEF_RAISED:
-	    topGC = bottomGC =
-		    (topBevel) ? borderPtr->lightGC : borderPtr->darkGC;
+	    if (height==1) {
+	    	topGC = (topBevel) ? borderPtr->lightGC : borderPtr->dark2GC;
+	    } else {
+		topGC = (topBevel) ? borderPtr->lightGC : borderPtr->darkGC;
+	    	bottomGC = (topBevel) ? borderPtr->bgGC : borderPtr->dark2GC;
+	    }	
 	    break;
 	case TK_RELIEF_SUNKEN:
-	    topGC = bottomGC =
-		    (topBevel) ? borderPtr->darkGC : borderPtr->lightGC;
+	    if (height==1) {
+		topGC = (topBevel) ? borderPtr->dark2GC : borderPtr->lightGC;
+	    } else {
+		topGC = (topBevel) ? borderPtr->darkGC : borderPtr->bgGC;
+	    	bottomGC = (topBevel) ? borderPtr->dark2GC : borderPtr->lightGC;
+	    }
 	    break;
 	case TK_RELIEF_RIDGE:
 	    topGC = borderPtr->lightGC;
@@ -359,11 +406,11 @@
 
     x1 = x;
     if (!leftIn) {
-	x1 += height;
+	x1 += height-1;
     }
     x2 = x+width;
     if (!rightIn) {
-	x2 -= height;
+	x2 -= height-1;
     }
     x1Delta = (leftIn) ? 1 : -1;
     x2Delta = (rightIn) ? -1 : 1;
@@ -373,24 +420,33 @@
     }
     bottom = y + height;
 
-    /*
-     * Draw one line for each y-coordinate covered by the bevel.
+    /* 
+     * if borderwidth is 1 just draw the line and get out
      */
-
-    for ( ; y < bottom; y++) {
-	/*
-	 * In some weird cases (such as large border widths for skinny
-	 * rectangles) x1 can be >= x2.  Don't draw the lines
-	 * in these cases.
-	 */
-
+    if (height==1) {
 	if (x1 < x2) {
 	    XFillRectangle(display, drawable,
+		topGC, x1, y, (unsigned) (x2-x1-topBevel), (unsigned) 1);
+	}
+    } else {
+        /*
+         * Draw one line for each y-coordinate covered by the bevel.
+         */
+     	for ( ; y < bottom; y++) {
+	    /*
+	     * In some weird cases (such as large border widths for skinny
+	     * rectangles) x1 can be >= x2.  Don't draw the lines
+	     * in these cases.
+	     */
+
+   	    if (x1 < x2) {
+	    XFillRectangle(display, drawable,
 		(y < halfway) ? topGC : bottomGC, x1, y,
-		(unsigned) (x2-x1), (unsigned) 1);
+		(unsigned) (x2-x1-topBevel), (unsigned) 1);
+	    }
+	    x1 += x1Delta;
+	    x2 += x2Delta;
 	}
-	x1 += x1Delta;
-	x2 += x2Delta;
     }
 }
 
@@ -436,10 +492,11 @@
 	    1, relief);
     Tk_3DVerticalBevel(tkwin, drawable, border, x+width-borderWidth, y,
 	    borderWidth, height, 0, relief);
+    
     Tk_3DHorizontalBevel(tkwin, drawable, border, x, y, width, borderWidth,
 	    1, 1, 1, relief);
     Tk_3DHorizontalBevel(tkwin, drawable, border, x, y+height-borderWidth,
-	    width, borderWidth, 0, 0, 0, relief);
+	    width, borderWidth, 0, 0, 0, relief);    
 }
 
 /*
@@ -527,7 +584,9 @@
 	return borderPtr->lightGC;
     } else if (which == TK_3D_DARK_GC){
 	return borderPtr->darkGC;
-    }
+    } else if (which == TK_3D_DARK2_GC) {
+	return borderPtr->dark2GC;
+    }    
     panic("bogus \"which\" value in Tk_3DBorderGC");
 
     /*
@@ -587,6 +646,9 @@
 	if (borderPtr->lightGC != None) {
 	    Tk_FreeGC(display, borderPtr->lightGC);
 	}
+	if (borderPtr->dark2GC != None) {
+	    Tk_FreeGC(display, borderPtr->dark2GC);
+	}
 	Tcl_DeleteHashEntry(borderPtr->hashPtr);
 	ckfree((char *) borderPtr);
     }
@@ -662,7 +724,7 @@
     } else if ((c == 's') && (strncmp(name, "sunken", length) == 0)) {
 	*reliefPtr = TK_RELIEF_SUNKEN;
     } else {
-	sprintf(interp->result, "bad relief type \"%.50s\": must be %s",
+	sprintf(interp->result, "bad relief type \"%.50s\":  must be %s",
 		name, "flat, groove, raised, ridge, or sunken");
 	return TCL_ERROR;
     }
@@ -1203,6 +1265,7 @@
  * Side effects:
  *	The lightGC and darkGC fields in borderPtr get filled in,
  *	if they weren't already.
+ * 
  *
  *----------------------------------------------------------------------
  */
@@ -1240,40 +1303,27 @@
 	 * to white, whichever is greater (the first approach works
 	 * better for unsaturated colors, the second for saturated ones).
 	 */
-
+	
 	darkColor.red = (60 * (int) borderPtr->bgColorPtr->red)/100;
 	darkColor.green = (60 * (int) borderPtr->bgColorPtr->green)/100;
 	darkColor.blue = (60 * (int) borderPtr->bgColorPtr->blue)/100;
+	
 	borderPtr->darkColorPtr = Tk_GetColorByValue(tkwin, &darkColor);
 	gcValues.foreground = borderPtr->darkColorPtr->pixel;
 	borderPtr->darkGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
 
+
+	/*
+	 * dark2 color is always black 
+	 */
+	gcValues.foreground = BlackPixelOfScreen(borderPtr->screen);
+	borderPtr->dark2GC = Tk_GetGC(tkwin, GCForeground, &gcValues);
+
 	/*
-	 * Compute the colors using integers, not using lightColor.red
-	 * etc.: these are shorts and may have problems with integer
-	 * overflow.
+	 * light color is always white	 
 	 */
 
-	tmp1 = (14 * (int) borderPtr->bgColorPtr->red)/10;
-	if (tmp1 > MAX_INTENSITY) {
-	    tmp1 = MAX_INTENSITY;
-	}
-	tmp2 = (MAX_INTENSITY + (int) borderPtr->bgColorPtr->red)/2;
-	lightColor.red = (tmp1 > tmp2) ? tmp1 : tmp2;
-	tmp1 = (14 * (int) borderPtr->bgColorPtr->green)/10;
-	if (tmp1 > MAX_INTENSITY) {
-	    tmp1 = MAX_INTENSITY;
-	}
-	tmp2 = (MAX_INTENSITY + (int) borderPtr->bgColorPtr->green)/2;
-	lightColor.green = (tmp1 > tmp2) ? tmp1 : tmp2;
-	tmp1 = (14 * (int) borderPtr->bgColorPtr->blue)/10;
-	if (tmp1 > MAX_INTENSITY) {
-	    tmp1 = MAX_INTENSITY;
-	}
-	tmp2 = (MAX_INTENSITY + (int) borderPtr->bgColorPtr->blue)/2;
-	lightColor.blue = (tmp1 > tmp2) ? tmp1 : tmp2;
-	borderPtr->lightColorPtr = Tk_GetColorByValue(tkwin, &lightColor);
-	gcValues.foreground = borderPtr->lightColorPtr->pixel;
+	gcValues.foreground = WhitePixelOfScreen(borderPtr->screen);
 	borderPtr->lightGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
 	return;
     }
@@ -1302,6 +1352,10 @@
 	gcValues.background = WhitePixelOfScreen(borderPtr->screen);
 	borderPtr->lightGC = Tk_GetGC(tkwin,
 		GCForeground|GCBackground|GCStipple|GCFillStyle, &gcValues);
+	
+	gcValues.foreground = gcValues.background;
+	borderPtr->dark2GC = Tk_GetGC(tkwin,
+		GCForeground|GCBackground, &gcValues);
 	return;
     }
 
@@ -1314,6 +1368,7 @@
     gcValues.foreground = WhitePixelOfScreen(borderPtr->screen);
     gcValues.background = BlackPixelOfScreen(borderPtr->screen);
     gcValues.stipple = borderPtr->shadow;
+
     gcValues.fill_style = FillOpaqueStippled;
     borderPtr->lightGC = Tk_GetGC(tkwin,
 	    GCForeground|GCBackground|GCStipple|GCFillStyle, &gcValues);
@@ -1325,4 +1380,109 @@
 	borderPtr->darkGC = borderPtr->lightGC;
 	borderPtr->lightGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
     }
+
+
+    gcValues.foreground = gcValues.background;
+    borderPtr->dark2GC = Tk_GetGC(tkwin,
+        GCForeground|GCBackground, &gcValues);
+}
+
+
+
+/*
+ *---------------------------------------------------------------------- 
+ * 
+ * Draw3DCircle --
+ * 	Draws a beveled circle
+ * 
+ * TODO: Fix circle code
+ *---------------------------------------------------------------------- 
+ */
+void Tk_Draw3DCircle(display, tkwin, d, x, y, wid, rad, relief, border)
+    Display *display;
+    Tk_Window tkwin;
+    Drawable d;
+    int x, y;          			/* position in d */
+    int wid;				/* border width */
+    int rad;
+    int relief;
+    Tk_3DBorder border;
+{
+    GC lightGC, darkGC, dark2GC, bgGC;
+    int half, i;
+    
+    if (relief==TK_RELIEF_SUNKEN) {	
+	lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC);
+	darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC);
+	dark2GC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK2_GC);
+	bgGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
+    } else {
+	darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC);
+	lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC);
+	bgGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK2_GC);
+	dark2GC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
+    }    
+    half = wid/2;
+    if (half>1) {
+	XSetLineAttributes(display, darkGC, half, LineSolid, CapButt,
+		JoinMiter);
+	XSetLineAttributes(display, lightGC, half, LineSolid, CapButt,
+		JoinMiter);
+	XSetLineAttributes(display, dark2GC, half, LineSolid, CapButt,
+		JoinMiter);
+	XSetLineAttributes(display, bgGC, half, LineSolid, CapButt, 
+		JoinMiter);
+    } 
+    /*
+     * These coords are based on trial and error
+     */
+    XDrawArc(display, d, dark2GC, x, y, rad*2-half, rad*2-half, 
+	60*64, 150*64);
+    XDrawArc(display, d, darkGC, x, y, rad*2, rad*2, 55*64, 160*64);
+    XDrawArc(display, d, lightGC, x, y, rad*2, rad*2, 35*64, -160*64);
+    XDrawArc(display, d, dark2GC, x+half, y+half, rad*2-half, 
+	rad*2-half, 60*64, 150*64);    
+    XDrawArc(display, d, bgGC, x, y, rad*2-half, rad*2-half, 
+	30*64, -150*64);
+    if (half>1) {
+	XSetLineAttributes(display, dark2GC, 0, LineSolid, CapButt,
+		JoinMiter);
+	XSetLineAttributes(display, lightGC, 0, LineSolid, CapButt,
+		JoinMiter);
+	XSetLineAttributes(display, darkGC, 0, LineSolid, CapButt,
+		JoinMiter);
+	XSetLineAttributes(display, bgGC, 0, LineSolid, CapButt,
+		JoinMiter);
+    }
 }
+
+
+
+/*
+ *----------------------------------------------------------------------
+ * 
+ * DrawCheckMark --
+ *     
+ *     Draws a 3D check mark on the drawable
+ * 
+ *----------------------------------------------------------------------
+ */
+void Tk_DrawCheckMark(display, tkwin, d, x, y, border)
+    Display *display;
+    Tk_Window tkwin;
+    Drawable d;
+    int x, y;          			/* position in d */
+    Tk_3DBorder border;
+{
+    GC lightGC, darkGC, dark2GC;
+    
+    lightGC = Tk_3DBorderGC(tkwin,border,TK_3D_LIGHT_GC);
+    darkGC = Tk_3DBorderGC(tkwin,border,TK_3D_DARK_GC);
+    dark2GC = Tk_3DBorderGC(tkwin,border,TK_3D_DARK2_GC);
+    XDrawLine(display, d, dark2GC, x+1, y+3, x+1, y+6); 
+    XDrawLine(display, d, lightGC, x, y+3, x, y+8);     
+    XDrawLine(display, d, lightGC, x, y+8, x+8, y);
+    XDrawLine(display, d, dark2GC, x, y+9, x+8, y+1);
+    XDrawLine(display, d, darkGC, x+1, y+9, x+8, y+2);
+}
+
